#include<iostream>
#include<poll.h>
#include<unistd.h>
int main()
{
  struct pollfd rfds;
  rfds.fd = 0;
  rfds.events = POLLIN;
  rfds.revents = 0;
  while(1){
  int n  = poll(&rfds,1, 1000);
  switch(n)
  {
    case 0:
      std::cout<<"timeout..."<<std::endl;
      break;
    case -1:
      std::cerr<<"poll error..."<<std::endl;
      break;
    default:
      std::cout<<"有事件发生..."<<std::endl;
      if(rfds.revents&POLLIN)
      {
        std::cout<<rfds.fd<<" 上面的读事件发生了"<<std::endl;
        char buffer[1024];
        ssize_t s = read(0, buffer, sizeof(buffer)-1);
        if(s>0)
        {
          buffer[s] = '\0';
          std::cout<<"有人说# "<<buffer<<std::endl;
        }
      }
      break;

  }
  }
  return 0;
}
